package cn.walls1717.ggkt.activity.controller;


import cn.walls1717.ggkt.activity.service.CouponInfoService;
import cn.walls1717.ggkt.model.activity.CouponInfo;
import cn.walls1717.ggkt.model.activity.CouponUse;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.vo.activity.CouponUseQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠券信息相关接口
 *
 * @author walls1717
 * @since 2022/07/18
 */
@Api(tags = "优惠券信息相关接口")
@RestController
@RequestMapping("/admin/activity/couponInfo")
public class CouponInfoController {

    @Autowired
    private CouponInfoService couponInfoService;

    @ApiOperation("获取优惠券分页列表")
    @GetMapping("{pageNum}/{pageSize}")
    public Result<Page<CouponInfo>> listPages(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        Page<CouponInfo> couponInfoPage = new Page<>(pageNum, pageSize);
        couponInfoService.page(couponInfoPage);
        return Result.success(couponInfoPage);
    }

    @ApiOperation("获取已经使用的优惠券分页列表")
    @GetMapping("couponUse/{pageNum}/{pageSize}")
    public Result<Page<CouponUse>> listPages(@PathVariable Integer pageNum, @PathVariable Integer pageSize, CouponUseQueryVo couponUseQueryVo) {
        Page<CouponUse> pageInfo = couponInfoService.listCouponUsePages(pageNum, pageSize, couponUseQueryVo);
        return Result.success(pageInfo);
    }

    @ApiOperation("获取优惠券")
    @GetMapping("get/{id}")
    public Result<CouponInfo> getCouponById(@PathVariable Long id) {
        CouponInfo couponInfo = couponInfoService.getById(id);
        return Result.success(couponInfo);
    }

    @ApiOperation("新增优惠券")
    @PostMapping("save")
    public Result<?> saveCoupon(@RequestBody CouponInfo couponInfo) {
        couponInfoService.save(couponInfo);
        return Result.success();
    }

    @ApiOperation("修改优惠券")
    @PutMapping("update")
    public Result<?> updateCouponById(@RequestBody CouponInfo couponInfo) {
        couponInfoService.updateById(couponInfo);
        return Result.success();
    }

    @ApiOperation("删除优惠券")
    @DeleteMapping("remove/{id}")
    public Result<?> deleteCouponById(@PathVariable Long id) {
        couponInfoService.removeById(id);
        return Result.success();
    }

    @ApiOperation("根据id列表删除优惠券")
    @DeleteMapping("batchRemove")
    public Result<?> deleteCouponsByIds(@RequestBody List<Long> idList){
        couponInfoService.removeByIds(idList);
        return Result.success();
    }
}

